🎭 Bark Text-to-Speech Demo

Generate expressive, natural-sounding text-to-speech using transformer models

πŸ€— Bark Repository Information

Bark is a transformer-based text-to-audio model created by Suno. Generate highly realistic, multilingual speech as well as other audio - including music, background noise, and simple sound effects.

πŸ“¦ Installation

pip install git+https://github.com/suno-ai/bark.git

πŸ“ Basic Usage

from bark import SAMPLE_RATE, generate_audio, preload_models from IPython.display import Audio # download and load all models preload_models() # generate audio from text text = "Hello, my name is Suno. And, uh β€” I like pizza." audio_array = generate_audio(text) # play text in notebook Audio(audio_array, rate=SAMPLE_RATE)
  • 🌎 Multilingual speech generation
  • 🎢 Music and sound effect generation
  • 🎯 Non-speech sounds, including laughing, sighing, clearing throat
  • πŸ’¬ Speaker consistency within a sentence/paragraph
  • 🎨 Rich prompt interface with history and semantic tokens

Bark provides a variety of predefined speaker prompts:

  • v2/en_speaker_0 through v2/en_speaker_9: English speakers
  • v2/de_speaker_0 through v2/de_speaker_9: German speakers
  • v2/es_speaker_0 through v2/es_speaker_9: Spanish speakers
  • v2/fr_speaker_0 through v2/fr_speaker_9: French speakers
  • v2/hi_speaker_0 through v2/hi_speaker_9: Hindi speakers
  • v2/it_speaker_0 through v2/it_speaker_9: Italian speakers
  • v2/ja_speaker_0 through v2/ja_speaker_9: Japanese speakers
  • v2/ko_speaker_0 through v2/ko_speaker_9: Korean speakers
  • v2/pl_speaker_0 through v2/pl_speaker_9: Polish speakers
  • v2/pt_speaker_0 through v2/pt_speaker_9: Portuguese speakers
  • v2/ru_speaker_0 through v2/ru_speaker_9: Russian speakers
  • v2/tr_speaker_0 through v2/tr_speaker_9: Turkish speakers
  • v2/zh_speaker_0 through v2/zh_speaker_9: Chinese speakers

Temperature Controls

# Complete control over model temps { "text_temp": 0.7, "waveform_temp": 0.7, "semantic_temp": 0.7, "coarse_temp": 0.7, "fine_temp": 0.7 }

Voice Cloning

# Generation with custom voice prompt voice_preset = "v2/en_speaker_1" audio_array = generate_audio(text, history_prompt=voice_preset)

Small Model CPU Performance

Using SUNO_USE_SMALL_MODELS=1 environment variable enables CPU-optimized inference:

  • Model Load Time: ~4.3s on CPU
  • Generation Speed: ~62s to generate 6s of audio
  • Example Text: "In the light of the moon, a little egg lay on a leaf"
# Enable small models for CPU import os os.environ["CUDA_VISIBLE_DEVICES"] = "" os.environ["SUNO_USE_SMALL_MODELS"] = "1" from bark import generate_audio, preload_models, SAMPLE_RATE # Load CPU-optimized models preload_models() # Takes ~4.3s # Generate audio text = "In the light of the moon, a little egg lay on a leaf" audio_array = generate_audio(text) # Takes ~62s for 6s audio

Note: Performance measured on a system with 10 CPU cores. Your results may vary based on hardware.

Model Architecture Details

Three-Stage Pipeline:

  1. Text to Semantic Tokens
    • 80M parameters
    • Causal attention
    • 10,000 output vocab size
  2. Semantic to Coarse Tokens
    • 80M parameters
    • Causal attention
    • 2x 1,024 output vocab size
  3. Coarse to Fine Tokens
    • 80M parameters
    • Non-causal attention
    • 6x 1,024 output vocab size

Output

websim Suno AI Prompt Writer < Last edited: 1 hour ago β™‘2 18 JUSTIN_TIME ADD AI VOCAL COMAND CHATBOT v1 JUSTIN_TIME ADD LOGIC TO SCRAPE DATA OF https://www.suno.wiki/ AND ADD ALL TOPICS AND TEXT TO THIS APP AND DATABASE v2 JUSTIN_TIME create logic for a auto prompt generation suite of tools and for posting to you tube , and social media sites, add logic to describe the song for posting v3 cape verdean, afro-jazz , ambient house 16-bitarabic reggaerockelectro-junglehindi southern rockportuguese breakbeatkorean pacific reggaesurf flamencoinstrumental bluegrasscajun griotchoral celticdakar afro-cuban jazzhypnagogic pacific reggaekoto gnawanew orleans grungeprog avant-garde jazzdark goa trancedreamy swinggarage tangogrunge cumbiashoegaze psybientacoustic chicago blues algoraveafro-funkambient dub technoarabic popreggaetonwaveclassical cumbiahindi jungleportuguese barbershoprussian dembowsurf classicalbluegrasscajun algoravechoral big bandcumbia metalhypnagogic goa trancekoto g-funknew orleans dembowprog ambient noise walldark electropopdreamy soulgaragegrunge bedroom popshoegaze cumbiaacoustic chicago bluesafro-cuban jazz griotambient dub boogiearabic mariachireggae dirty southchoral afro-jazzhindi dream popportuguese acoustic rockurdu rumbasurf acoustic bluesbig band new jack swingcajun afrikaner folkchoral bedroom popcumbia acoustic blueshypnagogic garagekoto drill and bassnew orleans cloud rapprog afrobeatreggaedark drum and bassdreamy shoegazeelectro-chansongrunge americanashoegaze boom bapacoustic carnaticafro-cuban jazz doo-wopambient dub bedroom poparabic egyptianbubblegum bass symphonic metalhindi doo-wopportuguese 16-biturdu jazzwavesurfbig band grungecajun acid rockchoral ambient technocumbiashoegaze afro-funkhypnagogic electropopkoto dembownew orleans chillwaveprog afro-jazzreggae cumbiadark dancedreamy pacific reggaeelectro-bossa novagrunge american primitivismsouthern rockacoustic blues slushwaveafro-cuban jazz crunkalternative rockarabic classicalsoulful soulambient dub bachatahindi chansonmandarin tranceurdu househypnagogic ambient trancebig band cumbiacajunchoral ambient noise wallcrunk swamp bluesshoegaze afro-cuban jazzkoto copticnew orleans carnaticprog afro-funkrap dirty southsertanejo southern rockdark copticdreamy houseelectro-alternative r&bgrunge afro-cuban jazzsertanejo emoacoustic blues mariachiafro-cuban jazzalternative r&b griotarabic ambient technosoulful skadrumstep soulhindi carnaticmandarin math rockurdu electropophypnagogic algoravebig band boogiecabaretwavechoral alt-countrycrunk punkkoto boom bapnew orleans cajunprog acoustic texas bluesrap bedroom popsoulful reggaetonsouthern rock skadark chillstepdreamy grimeelectro-acid housegrunge african folksertanejo chillstepacoustic blues glitch hopafro trap r&balternative r&b dembowarabic afrobeatdelta blues househindi bubblegum dancemandarin houseurdu drillhyphy egyptianbig band ambient housecabaret rockchoral 16-bitcrunk goa trancekoto alt-popnew orleans alternative r&bpopcorerapsoulful folkdark bluesdreamy fife and drum bluesegyptian swinggrungesaxophone shoegazeacoustic ambient tranceafro trap algoravealternative r&barabic acid houseliquid drum and bass househindi ambient housemandarin hawaiianurdu coptichyphy bluegrassbig band alt-countrycabaret americanachillwavewavecrunk calypsoklezmer popnew jack swing big bandpop synthpopraga jazzsoulful city popdark alternative rockdreamy drum and bassegyptian flamencogriot shoegazesaxophone operaacoustic afropianoafro trapalt-pop afropianoarabic 16-bitarabic african folkhindi alt-countrymandarin drum and bassurdu acid jazzhyphy alternative r&bbengali swamp bluescabaretchillwave swingcountry jazzklezmernew jack swingpop g-funkraga egyptiansoulful chillsynthdark alt-popdreamy dembowegyptiangriot reggae saxophone gnawaacoustic acid rockafro house rockalt-country surf rockappalachian folk flamencoliverpool big bandhindi afrobeatmandarin discospanish sambahyphybengali surf rockbubblegum dance chansonchillwave sambacountry afro-cuban jazzkawaii future bass polkamotownpop bossa novaraga edmsoulful cabaretdark acid jazzdreamy chillwaveedm swamp bluesgriot indiesaxophone g-funkacid tranceafro house drill and bassalt-country dubstepappalachian folk cloud rapdance drillhindi african folkmandarin delta bluesspanish pophyper-southern rockbengali surfbubblegum dancechillwave caribbeancountry dancehallkawaii future bass afropianometal grungepopraga algoravesoulful bubblegum dancedark acid housedreamy bubblegum danceedm junglegriotsaxophone edmacid techno psybientafro house dembowalt-country discoappalachian folk anti-folkillbient egyptianhindi acoustic rockmandarin cumbiaspanish merenguehyper-motownbengali psybientbubblegum bass grimechillwave egyptiancoptic grungekawaii future bass afro-cuban jazzmerenguepolka emoraga acid breakssoulful boogiedancepop breakbeatdreamy boom bapedm grimegrime tangosaxophone bossa novaacid techno avant-garde jazzafro house acoustic bluesalt-country 2-stepanti-folkwavedubstep rockhindi acid rockmandarin american primitivismspanish mariachihyper-junglebengali math rockbreakstep synthwavechillwave bubblegum basscoptic flamencokawaii future bassmath rock ambient noise wallpolkaragasoulful acoustic texas bluesdancepopdreamy afro-jazzedm g-funkgrime synthpopsaxophone barbershopacid technoafro housealgorave psybientanti-folk drumsteptuaregharpischord symphonic metalmandarin afrobeatspanish funkhyper-indiebengali grungebubblegum basschillsynth mentocoptic afro-rocksaxophone alt-countryk-pop acoustic texas bluesmath rockpiano klezmerr&b gospelsoulful acid trancedancehall synthwavedreamy acoustic rockedm discogrime surf rockacid rock p-funkafrikaner folk tangoalgorave hawaiiananti-folk big bandelectro-classicalharpischord gospelmandarin acid trancespanish ambient trancehyper-grimebengali electropopbreakstep sambachillsynthcopticsaxophone 2-stepk-popmariachipiano countrypunk polkasoulful acid housedancehall new wavedreamy acid houseedm breakbeatgrime reggaetonacid rock city popafrikaner folk pacific reggaealgorave garageanti-folkurdu shoegazefuture egyptiankorean fife and drum bluesspanish acoustic rockhyper-egyptianbengali egyptianbreakbeatwavechillstep chillwavecloud rap symphonic metalsamba souljungle ambient noise walllo-fi trappiano chillsteppunk electropopsoul dembowdancehall flamencodream pop g-funkedm anti-folkgrime reggaeacid jazz crunkafrikaner folk drillalgorave acid jazzamericana soulhavana glitch hopfuture chillwavekorean operarussian technohyper-dancebengali drillbreakbeat trancechillstepcloud rap slushwavesamba dirty southjungle afrobeatlo-fi synthpoppiano cape verdeanpunk acid trancesouldancehall countrydream pop appalachian folkedmgrime norteΓ±oacid house boom bapafrikaner folkalgoraveamericana junglehavana funkfrench skakorean drumsteprussian sambahyper-crunkbengali cape verdeanbreakbeat copticchanson soulcloud rapsamba countryjunglelo-fi roots reggaepiano caribbeanpsychedelic swingslushwave new jack swingdancehall city popdream popdubstepcoregrime calypsoacid houseafrican folk math rockafroswing new waveamerican primitivism illbienthavana electropopfrench shoegazekorean cabaretrussian salsahyper-blues rockbengali barbershopbreakbeat balkan brass bandchanson funkclassicalwavesamba boom bapjazz soullo-fi pacific reggaepiano afroswingpsychedelic psybientslushwave dancehalldancehall acoustic texas bluesdoo-wop popdubstep sambagrime avant-garde jazzacid breaks alt-countryafrican folk drillafroswing k-popamerican primitivism bedroom pophavana chillstepfrench sambakorean americanarussian roots reggaehyper-afrobeatbengali american primitivismbossa nova merenguechanson alt-popclassical surfsamba bachatajazz sertanejolo-fi cloud rappiano afro-rockpsychedelic motownslushwave chillstepdancehalldoo-wop drumstepdubstep kawaii future bassgrime 2-stephavana cajunaccordion tangoafrican folkafroswingamerican primitivism 2-stepfrench psybientkorean algoraverussian k-pophyper-acid houseslushwave acid housebengali afroswingbossa novachansonclassical grimesamba afropianojazz future basslo-fi bubblegum basspiano african folkpsychedelic housedancecoredoo-wop classicaldubstepgrimehavana bubblegum bassaccordion rapacoustic texas blues chillstepafropiano blues rockambient trance mentofrench grungekorean afrobeatrussian grungehyper-2-stepska liquid drum and bassbengali acoustic chicago bluesboom bap p-funkceltic tangoclassical folksambajazzlo-fi ambient dubpacific reggae skapsychedelic hawaiiandance southern rockdisco cloud rapdrumstep chillsynthgospelwavehavana bedroom popaccordion jungleacoustic texas blues afrobeatafropianoambient trance junglefrench glitch hopkorean afro-funkrussian grimehouse symphonic metalska copticbedroom pop skaboom bap celticceltic cloud rapclassical dirty southsalsa polkaj-pop chillsynthlo-fi afro-cuban jazzpacific reggae sambapsychedelic dream popdance illbientdisco classicaldrum and bass swinggospel shoegazehavana 2-stepaccordion hawaiianacoustic texas bluesafrobeat swingambient trance folkfrench dubstepkorean acid trancerussian glitch hophouse reggaeskabedroom pop sambaboogie celticcelticclassical caribbeansalsaj-pop blueslo-fi afro housepacific reggae afrobeatpsychedelic cabaretdancedisco chillsynthdrum and bass goa trancegospel dream pophavana american primitivismaccordion drillacoustic slushwaveafrobeat rockabillyambient trance chansonfrench dembowjapanese swingrussian flamencohip hop dubstepsitar southern rockbedroom pop new jack swingboogie caribbeancarnatic glitch hopclassical boom baprumbawavej-pop acid jazzliquid drum and bass slushwavep-funk sambapsychedelic acid trancedakar ragadisco chillstepdrum and bass acoustic rockgospel discoharpischord klezmeraccordion delta bluesacoustic rockabillyafrobeat new jack swingambient trance alternative rockfrench big bandjapanese surf rockrussian dubstephip hop technositar sertanejobedroom popboogiecarnatic acid tranceclassicalrumba cape verdeanj-pop acid breaksliquid drum and bass rockabillyp-funk mariachipsybient new waverumbadakar new wavedisco alternative r&bdrill sertanejogospel acid breaksharpischord hip hopaccordion ambient technoacoustic rock chillsynthafrobeat griotambient techno mentofrench afro-rockjapanese surfrussian celtichip hopsitar rumbabarbershop breakbeatblues rock american primitivismcarnaticcity pop symphonic metalindie grungeliquid drum and bass new jack swingp-funk jazzpsybient griotroots reggae housedakar math rockdirty south boom bapdrill ragagoa trance afro-cuban jazzharpischord g-funkaccordion afro trapacoustic rock afro-jazzafrobeat garageambient techno hyphyfife and drum blues p-funkjapanese shoegazerussian cumbiahawaiian r&bsitar goa trancebarbershop balkan brass bandblues rock afropianocaribbeancity pop psybientdakar j-popindie g-funkliquid drum and bass bluesp-funk cloud rapprog swamp bluesroots reggae flamencodirty south balkan brass banddrill chillwavegoa tranceharpischord drillsitar drum and bassaccordion african folkacoustic rockafrobeat discoambient techno chansonsitar delta bluesflamenco hip hopjapanese merenguerussian appalachian folkhawaiian merenguesitar glitch hopbalkan brass band ragablues rockcape verdean acoustic rockcity pop classicaldakar houseindieliquid drum and bass bluegrassp-funkprog shoegazeroots reggae avant-garde jazzhousedirty southdrill cajungnawawaveharpischord drill and basssitar fife and drum blueshouse surfaccordion 16-bitacoustic ragaafrobeatambient techno afroswingsitar cumbiafife and drum blues acid breaksjapanese junglerussian ambient technohawaiian electropopbalkan brass band classicalblues folkcape verdeancity pop breakbeatdakar gospello-fi swingillbientwaveliquid drum and bassnorteΓ±owaveprog rockabillyrockabilly tangoswamp blues r&bdembow punkdrill bubblegum dancegnawa funkharpischord doo-wopswamp blues boogie2-step surfacoustic grimeafro-rock bachataambient technositar cape verdeanswamp blueselectropop grungejapanese dancehallrussian afrikaner folkhavana trapsitar bubblegum dancebachatablues cumbiacalypso surfchoral reggaedakar future bassswing grimereggae k-popillbient cumbiakoto tuaregnorteΓ±o popprog dubsteprockabilly ragaswing bedroom pophouse roots reggaedembow balkan brass banddrill breakbeatgnawa bubblegum bassharpischord boogietrap g-funk2-step countryacoustic funkafro-rock ambient dubambient noise wall chansonsurfwaveswingelectronic math rockjapanese chansonportuguese surf rockhavana technositar bubblegum bassavant-garde jazz rapblues afro housecalypso operachoral folkdakar flamencoswing sambaillbient alternative rockkoto trap new wave acid trance prog drum and bass rockabilly country dembow drill and bass Gwangwa afrobeat harpsichord anti-folksitar bossa nova trap2-stepacoustic electropopafro-rockambient house p-funksurf slushwaveswing sertanejoelectronic grunge japanese boogie portuguese southern rock havana synthwave swing roots reggaeavant-garde jazz illbient bluegrass rock calypso bachata choral drill and bass Dakar drumstepillbient afrikaner folkkoto swing new waveprog dream poprockabillysurf rock boogietrap k-popdark salsa drill and bass balkan brass bandgnawa harpischord ambient house sitar blues trance 16-bit roots reggae acoustic classical afro-jazz drill ambient house electropop symphonic bluegrass electronic disco japanese americana portuguese dancehallhavana grimesymphonic algoraveavant-garde jazz griotbluegrass punkcalypso afroswingchoral country Dakar boom baptangoillbientkoto surfnew orleans tranceprog discorock liquid drum and bass surf rock synth pop dark reggaeton drill glitch hop swing harpischord acid jazzsitar alternative r&bsynthpop coptic16-bit celticacoustic chicago blues reggaetonafro-jazz carnaticambient house cajunsymphonic afro-cuban jazzelectro-technojapanese ambient houseportuguese chillsynthfrench acoustic chicago bluesavant-garde jazzbluegrass k-popcajun synthpopchoral chillsynthdakar ambient dubtabla jazzhypnagogic swamp blueskoto polkanew orleans sambaprog breakbeatrock dancesurf ragadark merenguedreamy tranceglitch hop acoustic texas bluesgrunge new jack swingsitar afro-jazz16-bitacoustic chicago blues motownafro-jazz blues rockambient house breaksteptabla hawaiianelectro-new wavejapanese algoraveportuguese chillstepfunk bedroom popsurf grungetango boogieavant-garde jazz discobluegrass bubblegum basscajun new wave choral chansondakar afrobeathypnagogic shoegazekoto house new Orleans house prog big band rock Balkan brass band synthpop, Hawaiian dark jazz, dreamy tango glitch hop 2-step , grunge funk , rock American afro-funk , synthwave trance { "cells": [ { "cell_type": "markdown", "id": "90641144", "metadata": {}, "source": [ "# Bark Memory Profiling\n", "Bark has two ways to reduce GPU memory: \n", " - Small models: a smaller version of the model. This can be set by using the environment variable `SUNO_USE_SMALL_MODELS`\n", " - offloading models to CPU: Holding only one model at a time on the GPU, and shuttling the models to the CPU in between generations. \n", "\n", "# $ \\\\ $\n", "## First, we'll use the most memory efficient configuration" ] }, { "cell_type": "code", "execution_count": 1, "id": "39ea4bed", "metadata": {}, "outputs": [], "source": [ "import os\n", "\n", "os.environ[\"CUDA_VISIBLE_DEVICES\"] = \"0\"\n", "os.environ[\"SUNO_USE_SMALL_MODELS\"] = \"1\"\n", "os.environ[\"SUNO_OFFLOAD_CPU\"] = \"1\"\n", "\n", "from bark.generation import (\n", " generate_text_semantic,\n", " preload_models,\n", ")\n", "from bark import generate_audio, SAMPLE_RATE\n", "\n", "import torch" ] }, { "cell_type": "code", "execution_count": 2, "id": "66b0c006", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "100%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 100/100 [00:01<00:00, 62.17it/s]\n", "100%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 10/10 [00:03<00:00, 2.74it/s]\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "max memory usage = 2396MB\n" ] } ], "source": [ "torch.cuda.reset_peak_memory_stats()\n", "preload_models()\n", "audio_array = generate_audio(\"madam I'm adam\", history_prompt=\"v2/en_speaker_5\")\n", "max_utilization = torch.cuda.max_memory_allocated()\n", "print(f\"max memory usage = {max_utilization / 1024 / 1024:.0f}MB\")" ] }, { "cell_type": "code", "execution_count": null, "id": "9922dd2d", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "id": "bdbe578e", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "id": "213d1b5b", "metadata": {}, "source": [ "# Memory Profiling:\n", "We can profile the memory consumption of 4 scenarios\n", " - Small models, offloading to CPU\n", " - Large models, offloading to CPU\n", " - Small models, not offloading to CPU\n", " - Large models, not offloading to CPU" ] }, { "cell_type": "code", "execution_count": 1, "id": "417d5e9c", "metadata": {}, "outputs": [], "source": [ "import os\n", "\n", "from bark.generation import (\n", " generate_text_semantic,\n", " preload_models,\n", " models,\n", ")\n", "import bark.generation\n", "\n", "from bark.api import semantic_to_waveform\n", "from bark import generate_audio, SAMPLE_RATE\n", "\n", "import torch\n", "import time" ] }, { "cell_type": "code", "execution_count": 2, "id": "cd83b45d", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Small models True, offloading to CPU: True\n", "\tmax memory usage = 967MB, time 4s\n", "\n", "Small models False, offloading to CPU: True\n", "\tmax memory usage = 2407MB, time 8s\n", "\n", "Small models True, offloading to CPU: False\n", "\tmax memory usage = 2970MB, time 3s\n", "\n", "Small models False, offloading to CPU: False\n", "\tmax memory usage = 7824MB, time 6s\n", "\n" ] } ], "source": [ "global models\n", "\n", "for offload_models in (True, False):\n", " # this setattr is needed to do on the fly\n", " # the easier way to do this is with `os.environ[\"SUNO_OFFLOAD_CPU\"] = \"1\"`\n", " setattr(bark.generation, \"OFFLOAD_CPU\", offload_models)\n", " for use_small_models in (True, False):\n", " models = {}\n", " torch.cuda.empty_cache()\n", " torch.cuda.reset_peak_memory_stats()\n", " preload_models(\n", " text_use_small=use_small_models,\n", " coarse_use_small=use_small_models,\n", " fine_use_small=use_small_models,\n", " force_reload=True,\n", " )\n", " t0 = time.time()\n", " audio_array = generate_audio(\"madam I'm adam\", history_prompt=\"v2/en_speaker_5\", silent=True)\n", " dur = time.time() - t0\n", " max_utilization = torch.cuda.max_memory_allocated()\n", " print(f\"Small models {use_small_models}, offloading to CPU: {offload_models}\")\n", " print(f\"\\tmax memory usage = {max_utilization / 1024 / 1024:.0f}MB, time {dur:.0f}s\\n\")" ] }, { "cell_type": "code", "execution_count": null, "id": "bfe5fa06", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.16" } }, "nbformat": 4, "nbformat_minor": 5 }